import { reqC1,reqC2,reqC3,reqAttrList } from "@/api/category" 
import { log } from "@soda/friendly-errors-webpack-plugin/src/output"

const state = {
  //品牌一级分类
  category1List: [],
  //品牌二级分类
  category2List: [],
  //品牌三级分类
  category3List: [],

}
const mutations = {
  //存储品牌一级分类
  SETCATEGORY1LIST(state,data){
    state.category1List = data
  },
  //存储品牌二级分类
  SETCATEGORY2LIST(state,data){
    state.category2List = data
  },
  //存储品牌三级分类
  SETCATEGORY3LIST(state,data){
    state.category3List = data
  },
  //清空品牌三级分类
  REMOVECATEGORY3LIST(state){
    state.category3List = []
  }
}
const actions = {
  //获取品牌一级分类
  async getC1({state,dispatch,getters,commit}) {
    let result = await reqC1()
    // console.log(result);
    commit('SETCATEGORY1LIST',result.data)
  },
  //获取品牌二级分类
  async getC2({state,dispatch,getters,commit},category1Id) {
    let result = await reqC2(category1Id)
    // console.log(result);
    commit('SETCATEGORY2LIST',result.data)
  },
  //获取品牌三级分类
  async getC3({state,dispatch,getters,commit},category2Id) {
    let result = await reqC3(category2Id)
    // console.log(result);
    commit('SETCATEGORY3LIST',result.data)
  },
  //清空三级分类数据
  setCategory3List({state,dispatch,getters,commit}){
    commit('REMOVECATEGORY3LIST')
  },
}

const getters = {
  category1List: state => state.category1List,
  category2List: state => state.category2List,
  category3List: state => state.category3List
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
